<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <p>{{msg}}</p>
        <input type="button" value="修改msg" @click="changeMsg">
        <p>{{str}}</p>
        <input type="button" value="修改str" @click="changeStr">
    </div>
</body>
</html>
<script src="./js/vue.global.js"></script>
<script>
    let app = Vue.createApp({
        data() {
            return {
                msg: 'hello',
                str: 'hihi'
            }
        },
        methods: {
            changeMsg() {
                this.msg += 1
            },
            changeStr() {
                this.str += 2
            }
        },
        // 使用时机：当数据渲染时，会调用(每个数据渲染都会被调用一次)
        renderTracked(event) {
            console.log('renderTracked:event.key', event.key);
        },
        // 使用时机：当数据修改时，会引起模板的重新渲染
        renderTriggered(event) {
            console.log('renderTracked:event.key', event.key);
            if (event.key === 'msg') {
                console.log('msg被修改了');
            }
        }
    })
    app.mount('#app')
</script>